<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PassportAction
 *
 * @author 志鹏
 */
class PassportAction extends CommonAction {
    
    public function Login() {
        if(IS_POST) {
            $user = D("UserRelation");
            $theUser = $user->relation(true)->getByUsername($_POST["login"]);
            
            if($theUser["status"] < 1) {
                $this->error("");
                //@todo 禁用用户
            }
            
            if(!$theUser or $theUser["password"] !== getPwd($_POST["password"])) {
                $this->error(L("operate_failed"));
            }
            foreach($theUser["groups"] as $g) {
                $theUser["group_ids"][] = $g["id"];
            }
            
            $_SESSION["user"] = $theUser;
            $this->redirect("/HOME/Index/index");
        } else {
            $this->display();
        }
    }
    
    public function logout() {
        session_destroy();
        $this->redirect("/HOME/Passport/login");
    }
    
}

?>
